Page({
  data: {
    schema:[
      {
        label:'页面最小宽度（ px 为单位）',
        prop:'minWidth',
        type:'number'
      },
      {
        label:'页面最大宽度（ px 为单位）',
        prop:'maxWidth',
        type:'number',
      },
      {
        label:'页面宽度（ px 为单位）',
        prop:'width',
        type:'number',
      },
      {
        label:'页面高度（ px 为单位）',
        prop:'height',
        type:'number',
      },
      {
        label:'页面最小高度（ px 为单位）',
        prop:'minHeight',
        type:'number',
      },
      {
        label:'页面最大高度（ px 为单位）',
        prop:'maxHeight',
        type:'number',
      },
      {
        label:'屏幕方向（ landscape 或 portrait ）',
        prop:'orientation',
        type:'text',
      }
    ],
    formData:{
      orientation: ''
    },
    title: '',
    result: '',
    remark: '',
    webUrl: '',
    theme: 'light',
    appear: false,
    observe: false,
    apiName: ''
  },
  onLoad(options) {
    console.log('options', options)
    wx.setNavigationBarTitle({
      title: options.title,
    })

    this.setData({
      title: options.title,
      zh:options.zh,
      remark: options.remark,
      webUrl: options.webUrl
    })
  },
  onUnload() {
    this._observer && this._observer.disconnect()
  },
  getFormData(e) {
    const formData = {}
    this.data.schema.forEach(item => {
      if(item.type === 'number') {
        if(e.detail.formData[item.prop]) {
          formData[item.prop] = +e.detail.formData[item.prop]
        }
      } else {
        formData[item.prop] = e.detail.formData[item.prop]
      }
    })
    console.log(formData, '=formData');
    this.setData({
      formData: formData
    })
  },
  choose1() {
    if(this._observer) {
      this._observer.disconnect()
      this._observer = null
    }
    this._observer = wx.createMediaQueryObserver(this)
    this._observer.observe(this.data.formData, (res) => {
      console.log(res, '====res');
      this.setData({
        result: res,
        apiName: 'MediaQueryObserver.observe'
      })
    })
  }
})
